package FactoryMethod;

import java.util.regex.Pattern;

public class PolymorphicFactory {	

	public Product createProduct(String query) {
		
		Product product=null;
		if(Pattern.matches(REGEX_FILE,query)) {
			product = new FileProduct();
		}
		else if (Pattern.matches(REGEX_WEB,query)) {
			product = new WebProduct();
		}
		else if (Pattern.matches(REGEX_DB,query)) {
			product = new DatabaseProduct();
		}
		else {
			product = new DefaultProduct();
		}
		
		return product.createProduct(query);
	}
	
	public static final String REGEX_WEB = "^(((ht|f)tp(s?))\\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\\-\\.]+\\.(com|edu|gov|mil|net|org|biz|info|name|museum|pl|us|ca|uk)(\\:[0-9]+)*(/($|[a-zA-Z0-9\\.\\,\\;\\?\\'\\\\\\+&amp;%\\$#\\=~_\\-]+))*$";
	public static final String REGEX_FILE = "^([a-zA-Z]\\:)(\\\\[^\\\\/:*?<>\"|]*(?<![ ]))*(\\.[a-zA-Z]{2,6})$";
	public static final String REGEX_DB = "db_"+"[a-zA-Z0-9]{1,100}";
}
